package com.freestyle.seatabusiness.account.config;

import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.freestyle.seatabusiness.api.Consts;
import com.freestyle.sentinel.GlobalHandlerImp;
import com.freestyle.sentinel.MethodArgs;
import com.freestyle.sentinel.SentinelResponseEntity;

/**
 * Created by rocklee on 2022/3/28 17:55
 */
public class SentinelGlobalHandler extends GlobalHandlerImp {
  @Override
  public Object globalBlockHandler(BlockException ex, MethodArgs methodArgs) {
    super.globalBlockHandler(ex,methodArgs);
    SentinelResponseEntity responseEntity= SentinelResponseEntity.fromErr(0,Consts.reBlockException,"触发限流");
    responseEntity.setMethod(methodArgs);
    return responseEntity;
  }

  @Override
  public Object globalFallBackHandler(Throwable throwable, MethodArgs methodArgs) {
    super.globalFallBackHandler(throwable,methodArgs);
    SentinelResponseEntity responseEntity=SentinelResponseEntity.fromErr(0,Consts.reThrowable,throwable.getMessage());
    responseEntity.setMethod(methodArgs);
    return responseEntity;
  }
}
